#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 2e6 + 10;

PII q[N];

int n, k;
LL res; 

int main()
{
	cin >> k >> n;
	
	for (int i = 0; i < n; i ++ )
	{
		int l, r;
		cin >> l >> r;
		
		q[i] = {l, r};
	}
	
	sort(q, q + n);
	
	for (int i = 0; i < n; i ++ )
	{
		if (q[i].y <= k)
		{
			res += q[i].y * q[i].x;
			k -= q[i].y;
			continue;
		}
		else
		{
			res += q[i].x * k;
			break;	
		}
	}	
	
	cout << res << endl;
	
	return 0;
	
}
